package com.musicdaze.graphics;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

import com.musicdaze.utils.Utils;

public class Splash extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private BufferedImage image;

	public Splash(String resource){
		super();
		setUndecorated(true);
		setResizable(false);
		setBackground(Color.black);
		InputStream is = Utils.loadResource(resource);
		if (is ==null){
			return;
		}
		try {
			image = ImageIO.read(is);
			JLabel lab = new JLabel(new ImageIcon(image));
			this.add(lab);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void showSplash(){
		SwingUtilities.invokeLater(new Runnable(){

			@Override
			public void run() {
				Splash.this.pack();
				Splash.this.setLocationRelativeTo(null);
				Splash.this.setVisible(true);
			}});
	}
	public void closeSplash(){
		SwingUtilities.invokeLater(new Runnable(){

			@Override
			public void run() {
				Splash.this.setVisible(false);
			}});		
	}
}
